<?php 
require_once 'init.php';
require_once 'ckLogin.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$db = new dbConn();
$db->DB_NAME="Pictures";
//提交处理
if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
	$pic_id=$_POST['pic_id'];
	$description=htmlspecialchars($_POST['description']);
	$db->sql="UPDATE Pictures SET Description = '".$description."' WHERE Identifier = ".$pic_id;
	$db->doExecute();
}
//总条数
if($_GET['startTime'] && $_GET['endTime']){
	$db->sql="select count(Identifier) count from Pictures where PublishDate>='".$_GET['startTime']."' and PublishDate<='".$_GET['endTime']."'";
	$count = $db->doResult2();
	$count = $count['count'];
}else{
	$count = $db->getCount();
}
//$count>0时
if($count>0){
	//总页数
	if($count%PAGESIZE==0){
		$maxPage = $count/PAGESIZE;
	}else{
		$maxPage = (int)($count/PAGESIZE)+1;
	}
	//获取的30条
	if(empty($_GET['page'])){$page = 1;}else{$page=$_GET['page'];}
	$start = ($page-1)*PAGESIZE;
	
	if($_GET['startTime'] && $_GET['endTime']){
		$db->sql="select * from Pictures where PublishDate>='".$_GET['startTime']."' and PublishDate<='".$_GET['endTime']."' order by PublishDate desc limit ".$start.",30";
		$pictures = $db->doResultList2();
	}else{
		$pictures = $db->getLimit($start,PAGESIZE,'PublishDate',0);
	}
	//分页处理
	if($maxPage>=5){
		if($page<=2){
			$pages=array(1,2,3,4,5);
		}elseif($page>=($maxPage-1)){
			$pages=array($maxPage-4,$maxPage-3,$maxPage-2,$maxPage-1,$maxPage);
		}else{
			$pages=array($page-2,$page-1,$page,$page+1,$page+2);
		}
	}else{
		for($i=1;$i<=$maxPage;$i++){
			$pages[]=$i;
		}
	}
}
//url是否有值
if($_GET['startTime'] && $_GET['endTime']){
	$url="startTime=".$_GET['startTime'].'&endTime='.$_GET['endTime'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simpla Admin</title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css"
	media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css"
	media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css"
	media="screen" />
<!-- Colour Schemes
		Default colour scheme is green. Uncomment prefered stylesheet to use it.
		<link rel="stylesheet" href="resources/css/blue.css" type="text/css" media="screen" />
		<link rel="stylesheet" href="resources/css/red.css" type="text/css" media="screen" />  
		-->
<!-- Internet Explorer Fixes Stylesheet -->
<!--[if lte IE 7]>
			<link rel="stylesheet" href="resources/css/ie.css" type="text/css" media="screen" />
		<![endif]-->
<!--                       Javascripts                       -->
<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.7.2.min.js"></script>

<script type="text/javascript">
$(function($) {
	//搜索
	$("#zhixing").click(function(){
		var startTime = $('#startTime').val();
		var endTime   = $('#endTime').val();
		if(startTime && endTime){
			//window.open('downloadExcel2.php?startTime='+startTime+'&endTime='+endTime);
		}else{
			alert("时间不能为空");
		}
	});
	//导出
	$("#download").click(function(){
		var startTime = $('#startTime').val();
		var endTime   = $('#endTime').val();
		if(startTime && endTime){
			if(startTime > endTime){
				alert('开始时间大于结束时间');
				return false;
			}else{
				window.open('downloadExcel2.php?startTime='+startTime+'&endTime='+endTime);
			}
		}else{
			alert("时间不能为空");
			return false;
		}
	});
});

</script>

<!-- jQuery Configuration -->
<script type="text/javascript" src="resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
<!-- jQuery my97datepicker -->
<script type="text/javascript" src="resources/scripts/My97DatePicker/WdatePicker.js"></script>
<!--[if IE]><script type="text/javascript" src="resources/scripts/jquery.bgiframe.js"></script><![endif]-->
<!-- Internet Explorer .png-fix -->
<!--[if IE 6]>
			<script type="text/javascript" src="resources/scripts/DD_belatedPNG_0.0.7a.js"></script>
			<script type="text/javascript">
				DD_belatedPNG.fix('.png_bg, img, li');
			</script>
		<![endif]-->

</head>
<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		
		<div id="main-content">
			
			<!-- Page Head -->
			<h2>欢迎使用<?php echo APPLICATION;?>管理后台</h2>
			<p id="page-intro">接下来你要做什么呢亲？</p>
			<div class="clear"></div>
			<!-- End .clear -->
			<div class="content-box">
				<!-- Start Content Box -->

				<div class="content-box-header">

					<h3>Content box</h3>

					<!-- <ul class="content-box-tabs">
						<li><a href="#tab1" class="default-tab">Table</a></li>
						href must be unique and match the id of target div
						<li><a href="#tab2">Forms</a></li>
					</ul> -->

					<div class="clear"></div>

				</div>
				<!-- End .content-box-header -->

				<div class="content-box-content">
				
					<p>
					<form method="get" action="">
						时间：
						<input type="text" id="startTime" name="startTime" onClick="WdatePicker()" value="<?php echo $_GET['startTime'];?>"/> 
						--
						<input type="text" id="endTime" name="endTime" onClick="WdatePicker()" value="<?php echo $_GET['endTime'];?>"/>
						&nbsp;&nbsp;&nbsp;
						<button class="button" id="zhixing" type="submit">搜索</button>
						&nbsp;&nbsp;&nbsp;
						<button class="button" id="download" type="submit">导出</button>
					</form>
					</p>
					<hr />
					<div class="clear"></div>
					<div class="tab-content default-tab" id="tab1">
						<!-- This is the target div. id must match the href of this div's tab -->

						<table>
							<thead>
								<tr>
									<th><input class="check-all" type="checkbox" /></th>
									<th>编号</th>
									<th>图片</th>
									<th>日期</th>
									<th>描述</th>
									<th>分享</th>
									<th>收藏</th>
									
								</tr>

							</thead>

							<tbody>
							<?php 
							if($count>0):
								foreach ($pictures as $key=>$item):
							?>
								<tr>
									<td><input type="checkbox" name="picSel" value="<?php echo $item['Identifier'];?>"/></td>
									<td><?php echo $item['Identifier'];?></td>
									<td><a href="<?php echo '../'.$item['Address'];?>" title="<?php echo $item['Description'];?>" target="_blank"><img src="<?php echo '../'.$item['Address'];?>" alt="" width="50px;" height="50px;"/></a></td>
									<td><?php echo $item['PublishDate'];?></td>
									<td><?php echo $item['Description'];?></td>
									<td><?php echo $item['Shared'];?></td>
									<td><?php echo $item['Collected'];?></td>
									
								</tr>
							<?php 
								endforeach;
							else:
							?>
								<tr style="height: 70px;text-align: center;font-size: 40px;">
									<td colspan="7" style="text-align: center;">没有图片！！！</td>
								</tr>
							<?php 
							endif;
							?>
							</tbody>
							
							<tfoot>
								<tr>
									<td colspan="7">
										<div class="bulk-actions align-left">
											
										</div>

										<div class="pagination">
										<?php if($count>0):?>
											<a href="downloadExcel.php?<?php if($url) echo $url.'&';?>page=1" title="First Page">&laquo; First</a>
											<a href="downloadExcel.php?<?php if($url) echo $url.'&';?>page=<?php if($page<=1) echo 1;else echo $page-1;?>" title="Previous Page">&laquo; Previous</a>
											<?php foreach ($pages as $item):?> 
											<a href="downloadExcel.php?<?php if($url) echo $url.'&';?>page=<?php echo $item;?>" class="number <?php if($item == $page) echo 'current';?>" title="<?php echo $item;?>"><?php echo $item;?></a>
											<?php endforeach;?>
											<a href="downloadExcel.php?<?php if($url) echo $url.'&';?>page=<?php if($page>=$maxPage) echo $maxPage;else echo $page+1;?>" title="Next Page">Next &raquo;</a>
											<a href="downloadExcel.php?<?php if($url) echo $url.'&';?>page=<?php echo $maxPage;?>" title="Last Page">Last &raquo;</a>
											&nbsp;Total : <?php echo $maxPage;?>
										<?php endif;?>
										</div> <!-- End .pagination -->
										<div class="clear"></div>
									</td>
								</tr>
							</tfoot>

						</table>

					</div>
					<!-- End #tab1 -->


				</div>
				<!-- End .content-box-content -->

			</div>
			<!-- End .content-box -->

			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
